package com.plz.afmt.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.plz.web.util.ReqResUtil;
import com.plz.web.base.vo.PagerResult;
import com.plz.web.base.dto.Resq;
import com.plz.web.base.dto.Resp;
import com.plz.web.base.dto.BaseIdDto;
import com.plz.web.base.dto.BaseIdsDto;

import javax.validation.Valid;
import java.util.List;

import org.springframework.web.bind.annotation.RestController;
import com.plz.web.base.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import com.plz.afmt.service.EnterprisesService;


import com.plz.afmt.dto.EnterprisesDto;
import com.plz.afmt.dto.EnterprisesQueryDto;
import com.plz.afmt.vo.EnterprisesVo;

/**
 * <p>
 * 企业表 管理
 * </p>
 *
 * @author jzc
 */
@Slf4j
@RestController
@Api(tags = "企业表-管理")
@RequestMapping("/admin/enterprises")
public class EnterprisesController extends BaseController {

    @Autowired
    private EnterprisesService enterprisesService;

    /**
     * 查询分页数据
     */
    @ApiOperation(value = "查询分页数据")
    @PostMapping("/page")
    public Resp<PagerResult<EnterprisesVo>> page(@RequestBody Resq<EnterprisesQueryDto> requestBean) {
        EnterprisesQueryDto dto = getReqData(requestBean);
        PagerResult<EnterprisesVo> result = enterprisesService.pageQuery(dto);
        return getRes(result);
    }

    @ApiOperation(value = "查询数据")
    @PostMapping("/list")
    public Resp<List<EnterprisesVo>> list() {
        List<EnterprisesVo> result = enterprisesService.listFor();
        return getRes(result);
    }

    /**
     * 根据id查询
     */
    @ApiOperation(value = "根据id查询数据")
    @PostMapping(value = "/detail")
    public Resp<EnterprisesVo> getById(@Valid @RequestBody Resq<BaseIdDto> requestBean) {
        BaseIdDto dto = getReqData(requestBean);
        EnterprisesVo result = enterprisesService.detail(dto.getId());
        return getRes(result);
    }

    /**
     * 新增
     */
    @ApiOperation(value = "新增数据")
    @PostMapping(value = "/add")
    public Resp<Boolean> add(@Valid @RequestBody Resq<EnterprisesDto> requestBean) {
        EnterprisesDto dto = getReqData(requestBean);
        Boolean result = enterprisesService.add(dto) != null;
        return getRes(result);
    }

    /**
     * 修改
     */
    @ApiOperation(value = "更新数据")
    @PostMapping(value = "/update")
    public Resp<Boolean> update(@Valid @RequestBody Resq<EnterprisesDto> requestBean) {
        EnterprisesDto dto = getReqData(requestBean);
        Boolean result = enterprisesService.update(dto) != null;
        return getRes(result);
    }

    /**
     * 更新会员时间数据
     */
    @ApiOperation(value = "更新会员时间数据")
    @PostMapping(value = "/update-vip-time")
    public Resp<Boolean> updateVipTime(@Valid @RequestBody Resq<EnterprisesDto> requestBean) {
        EnterprisesDto dto = getReqData(requestBean);
        Boolean result = enterprisesService.updateVipTime(dto);
        return getRes(result);
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除数据")
    @PostMapping(value = "/del")
    public Resp<Boolean> delete(@Valid @RequestBody Resq<BaseIdsDto> requestBean) {
        BaseIdsDto dto = getReqData(requestBean);
        Boolean result = enterprisesService.removeByIds(dto.getIds());
        return getRes(result);
    }

}
